<template>
    <div>123</div>
    <button @click="click_export">点击导出</button>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
// import { saveAs } from 'file-saver';
import * as XLSX from 'xlsx';
 
const exportExcel = () => {
      // 假设你已经有了一个Excel工作簿(workbook)和工作表(sheet)的引用
      let workbook = XLSX.readFile('D:/Firefox_download/spreadsheet.xlsx');
      let sheet = workbook.Sheets[workbook.SheetNames[0]];
 
      // 添加新的数据到工作表
      const newData = [
        ['新数据1', '新数据2', '新数据3'],
        ['新数据4', '新数据5', '新数据6']
      ];
      newData.forEach((row, index) => {
        const rowNumber = sheet['A' + (index + 2)] ? index + 2 : index + 1;
        row.forEach((cell, cellIndex) => {
          sheet[`${String.fromCharCode(65 + cellIndex)}${rowNumber}`] = {
            t: 's',
            v: cell,
            z: XLSX.utils.encode_cell({ c: cellIndex, r: rowNumber - 1 }),
          };
        });
      });
 
      // 写入新的工作表到工作簿
      workbook.Sheets[workbook.SheetNames[0]] = sheet;
 
      // 导出工作簿
      XLSX.writeFile(workbook, 'new_spreadsheet.xlsx');
    };

function click_export(){
    console.log("click_export");
    
    exportExcel()
}
</script>
<style scoped></style>
